/*
 * @Author: 刘鑫
 * @Date: 2020-11-13 20:57:40
 * @LastEditors: 刘鑫
 * @LastEditTime: 2020-11-13 21:34:03
 * @Description:
 */
import { getHotSearch, getSearch, getSearchTips } from "@/api/home.js";
const state = {
  hotList: [],
  rankList: [],
  articleList: [],
  searchList: [],
  searchHistory: []
};
const mutations = {
  updateHotList(state, payload) {
    state.hotList = payload;
  },
  updateSearchList(state, payload) {
    state.rankList = payload.rankList;
    state.articleList = payload.articleList;
    // console.log("search>>>>>",state.rankList,'articleList',state.articleList)
  },
  updateSearchTips(state, payload) {
    state.searchList = payload;
    //    console.log('tips',state.searchList)
  },
  updateSearchHistory(state, payload) {
    state.searchHistory.unshift(payload.item);
  },
  updateDeleteSearch(state) {
    state.searchHistory.length = 0;
    console.log(111, state.searchHistory);
  }
};
const actions = {
  async getHotList({ commit }, payload) {
    let res = await getHotSearch(payload);
    console.log(res);
    commit("updateHotList", res.dataList);
  },
  async getSearchList({ commit }, payload) {
    let res = await getSearch(payload);
    commit("updateSearchList", res);
  },
  async getSearchTipList({ commit }, payload) {
    let res = await getSearchTips(payload.dataList);
    commit("updateSearchTips", res);
  },
  async getSearchHistory({ commit }, payload) {
    commit("updateSearchHistory", payload);
  },
  async deleteSearchHistory({ commit }) {
    commit("updateDeleteSearch");
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  actions
};
